package client;

import java.awt.BorderLayout;
import java.awt.Rectangle;
import java.beans.PropertyVetoException;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.net.Socket;
import javax.swing.JDesktopPane;
import javax.swing.JInternalFrame;
import javax.swing.JPanel;
/**
 * @author KEM
 *
 */
class PartnerHandler extends Thread {

    private JDesktopPane pDesktop = null;
    private Socket client = null;
    private JInternalFrame internalFrame = null;
    private JPanel pScreen = null;
    
    public PartnerHandler(Socket client, JDesktopPane desktop) {
        this.client = client;
        this.pDesktop = desktop;
        start();
    }

    public void loadGui(){
    	internalFrame = new JInternalFrame("Partner desktop" + client.getInetAddress(),
                true, true, true);
    	pScreen = new JPanel();
        internalFrame.setLayout(new BorderLayout());
        internalFrame.getContentPane().add(pScreen,BorderLayout.CENTER);
        internalFrame.setSize(100,100);
        pDesktop.add(internalFrame);
        try {
            internalFrame.setMaximum(true);
        } catch (PropertyVetoException ex) {
        }
        pScreen.setFocusable(true);
        internalFrame.setVisible(true);
    }

    @Override
    public void run(){
        Rectangle screenSize = null;
        ObjectInputStream ois = null;
        loadGui();
        try{
            ois = new ObjectInputStream(client.getInputStream());
            screenSize =(Rectangle) ois.readObject();
        }catch(IOException ex){
        }catch(ClassNotFoundException ex){
        }        
        ScreenReceiver screenReceiver = new ScreenReceiver( ois, pScreen);
        CommandSender commandSender = new CommandSender(client,pScreen,screenSize);
    }

}
